# coding=utf-8
import copy
from ..ToolsConfig import *


class MountDataKeyName(object):
    Animation = 'animation'
    AnimationController = 'animation_controller'
    ScriptAnimation = 'script_animation'
    Geometry = 'geometry'
    Texture = 'texture'
    RenderController = 'render_controller'
    Material = 'material'


class BasicMountData(dict):
    """
    外挂模型动画基本数据字典
    """

    def __init__(self, _data=None):
        # type:(dict) -> None
        if _data is None:
            _data = {}
        data = {
            MountDataKeyName.Animation: {},
            MountDataKeyName.AnimationController: {},
            MountDataKeyName.ScriptAnimation: {},
            MountDataKeyName.Geometry: {},
            MountDataKeyName.Texture: {},
            MountDataKeyName.RenderController: [],
            MountDataKeyName.Material: {}
        }
        for kv in _data.items():
            data[kv[0]] = kv[1]
        super(BasicMountData, self).__init__(data)

    def Copy(self):
        """
        继承本字典的所有信息
        """
        return copy.deepcopy(self)

    def SetAnimationData(self, value):
        self[MountDataKeyName.Animation] = value
        return self

    def AddAnimationData(self, key, value):
        self[MountDataKeyName.Animation][key] = value
        return self

    def SetAnimationControllerData(self, value):
        self[MountDataKeyName.AnimationController] = value
        return self

    def AddAnimationControllerData(self, key, value):
        self[MountDataKeyName.AnimationController][key] = value
        return self

    def SetScriptAnimationData(self, value):
        self[MountDataKeyName.ScriptAnimation] = value
        return self

    def AddScriptAnimationData(self, key, value):
        self[MountDataKeyName.ScriptAnimation][key] = value
        return self

    def SetGeometryData(self, value):
        self[MountDataKeyName.Geometry] = value
        return self

    def AddGeometryData(self, key, value):
        self[MountDataKeyName.Geometry][key] = value
        return self

    def SetTextureData(self, value):
        self[MountDataKeyName.Texture] = value
        return self

    def AddTextureData(self, key, value):
        self[MountDataKeyName.Texture][key] = value
        return self

    def SetRenderControllerData(self, value):
        self[MountDataKeyName.RenderController] = value
        return self

    def AddRenderControllerData(self, value):
        self[MountDataKeyName.RenderController].append(value)
        return self

    def SetMaterialData(self, value):
        self[MountDataKeyName.Material] = value
        return self

    def AddMaterialData(self, key, value):
        self[MountDataKeyName.Material][key] = value
        return self


def RemoveItem(playerId, data):
    # type:(Union[str,int],BasicMountData)->None
    """
    删除外挂模型
    """
    playerRenderComp = clientCompFactory.CreateActorRender(playerId)
    RemoveRenderController(playerRenderComp, data['render_controller'])


def LoadItem(playerId, data):
    # type:(Union[str,int],BasicMountData)->None
    """
    加载外挂模型贴图动画渲染器等
    """
    playerRenderComp = clientCompFactory.CreateActorRender(playerId)
    LoadGeometry(playerRenderComp, data['geometry'])
    LoadTexture(playerRenderComp, data['texture'])
    LoadRenderController(playerRenderComp, data['render_controller'])
    LoadAnimation(playerRenderComp, data['animation'])
    LoadAnimationController(playerRenderComp, data['animation_controller'])
    LoadScriptAnimation(playerRenderComp, data['script_animation'])
    LoadMaterial(playerRenderComp, data['material'])


def RemoveGeometry(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.RemovePlayerGeometry(_[0])


def RemoveRenderController(playerRenderComp, data):
    for _ in data:
        playerRenderComp.RemovePlayerRenderController(_)


def RemoveAnimationController(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.RemovePlayerAnimationController(_[0])


def LoadGeometry(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.AddPlayerGeometry(*_)


def LoadTexture(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.AddPlayerTexture(*_)


def LoadRenderController(playerRenderComp, data):
    for _ in data:
        playerRenderComp.AddPlayerRenderController(_)


def LoadAnimation(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.AddPlayerAnimation(*_)


def LoadAnimationController(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.AddPlayerAnimationController(*_)


def LoadScriptAnimation(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.AddPlayerScriptAnimate(*_)


def LoadMaterial(playerRenderComp, data):
    for _ in data.items():
        playerRenderComp.AddPlayerRenderMaterial(*_)
